package com.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by Administrator on 2018/11/12/012.
 */
public class TestChannel {
    public static void main(String[] args) throws Exception {
        FileInputStream in = new FileInputStream("src/nio_test_value.txt");
        FileOutputStream out = new FileOutputStream("src/out.txt");

        FileChannel inChannel = in.getChannel();
        FileChannel outChannel = out.getChannel();

        ByteBuffer bf = ByteBuffer.allocate(10);
        while (true) {
            bf.clear();
            int read = inChannel.read(bf);
            System.out.println("read:" + read);
            if (read < 0) {
                System.out.println("break read:" + read);
                break;
            }

            bf.flip();
            outChannel.write(bf);
        }

    }
}
